/**
 * 
 */
package com.study.regx;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Administrator
 * @date 2019年6月12日
 */
public class Demo {

	public static void main(String[] args) {
		String pattern = "^https://([a-zA-Z0-9.]{0,})(/).*";
        Pattern p = Pattern.compile(pattern);
        String line = "https://xxx.yyy.cn/aa/bb.jpg";
        Matcher m = p.matcher(line);

        if(m.find()){
            //匹配结果
            System.out.println("=" + m.group());
            System.out.println("=" + m.group(0));
            System.out.println("=" + m.group(1));
            System.out.println("=" + m.group(2));
        }
        //替换
        System.out.println(line.replaceAll(pattern, ""));
        
        String text="(content:\"rcpt to root\";pcre:\"word\";)";
        String rule1="content:\".+\"";    //贪婪模式
        String rule2="content:\".+?\"";    //非贪婪模式
        
        System.out.println("文本："+text);
        System.out.println("贪婪模式："+rule1);
        Pattern p1 =Pattern.compile(rule1);
        Matcher m1 = p1.matcher(text);
        while(m1.find()){
            System.out.println("匹配结果："+m1.group(0));
        }
        
        System.out.println("非贪婪模式："+rule2);
        Pattern p2 =Pattern.compile(rule2);
        Matcher m2 = p2.matcher(text);
        while(m2.find()){
            System.out.println("匹配结果："+m2.group(0));
        }
        
        Matcher m3 = Pattern.compile("\\b(\\w+)\\b\\s+\\1\\b").matcher("go go");
        System.out.println(m3.find()+","+m3.group(1));
	}
}
